package com.fdb.efp.limit.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.limit.service.dao.LmtAdjustThirdDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.limit.service.domain.LmtAdjustThird;
import com.fdb.efp.limit.service.facade.LmtAdjustThirdService;
import com.fdb.efp.limit.service.vo.LmtAdjustThirdVO;

/**
 * 第三方额度调整申请表
 * @author ligm
 * @date 2019-03-04
 */
@Service("lmtAdjustThirdService")
public class LmtAdjustThirdServiceImpl implements LmtAdjustThirdService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(LmtAdjustThirdServiceImpl.class);

	@Autowired
	private LmtAdjustThirdDao lmtAdjustThirdDao;

	/**
	 * 新增操作
	 */
	public int insertLmtAdjustThird(LmtAdjustThirdVO inLmtAdjustThirdVo) {
		logger.debug("当前新增数据为:"+ inLmtAdjustThirdVo.toString());
		int num = 0;
		try {
			LmtAdjustThird lmtAdjustThird = new LmtAdjustThird();
			beanCopy(inLmtAdjustThirdVo, lmtAdjustThird);
			num = lmtAdjustThirdDao.insertLmtAdjustThird(lmtAdjustThird);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(LmtAdjustThirdVO inLmtAdjustThirdVo) {
		logger.debug("当前删除数据条件为:"+ inLmtAdjustThirdVo);
		int num = 0;
		try {
			LmtAdjustThird lmtAdjustThird = new LmtAdjustThird();
			beanCopy(inLmtAdjustThirdVo, lmtAdjustThird);
			num = lmtAdjustThirdDao.deleteByPk(lmtAdjustThird);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inLmtAdjustThirdVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(LmtAdjustThirdVO inLmtAdjustThirdVo) {
		logger.debug("当前修改数据为:"+ inLmtAdjustThirdVo.toString());
		int num = 0;
		try {
			LmtAdjustThird lmtAdjustThird = new LmtAdjustThird();
			beanCopy(inLmtAdjustThirdVo, lmtAdjustThird);
			num = lmtAdjustThirdDao.updateByPk(lmtAdjustThird);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inLmtAdjustThirdVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public LmtAdjustThirdVO queryByPk(LmtAdjustThirdVO inLmtAdjustThirdVo) {

		logger.debug("当前查询参数信息为:"+ inLmtAdjustThirdVo);
		try {
			LmtAdjustThird queryLmtAdjustThird = new LmtAdjustThird();
			beanCopy(inLmtAdjustThirdVo, queryLmtAdjustThird);
			LmtAdjustThird queryRslLmtAdjustThird = lmtAdjustThirdDao.queryByPk(queryLmtAdjustThird);
			if (Objects.nonNull(queryRslLmtAdjustThird)) {
				LmtAdjustThirdVO outLmtAdjustThirdVo = beanCopy(queryRslLmtAdjustThird, new LmtAdjustThirdVO());
				logger.debug("当前查询结果为:"+ outLmtAdjustThirdVo.toString());
				return outLmtAdjustThirdVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtAdjustThirdVO> queryAllOwner(LmtAdjustThirdVO lmtAdjustThirdVo) {
		/**
		 * 时间区间的处理
		 */
		if(lmtAdjustThirdVo.getSignDate_b2e() != null && lmtAdjustThirdVo.getSignDate_b2e().toString() !="[]") {
			logger.info(lmtAdjustThirdVo.getSignDate_b2e().toString());
			lmtAdjustThirdVo.setSignDate_b(lmtAdjustThirdVo.getSignDate_b2e().get(0));
			lmtAdjustThirdVo.setSignDate_e(lmtAdjustThirdVo.getSignDate_b2e().get(1));
		}
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<LmtAdjustThirdVO> list = null;
		try {
			List<LmtAdjustThird> lmtAdjustThirds = lmtAdjustThirdDao.queryAllOwnerByPage(lmtAdjustThirdVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ lmtAdjustThirds.size());
			pageSet(lmtAdjustThirds, lmtAdjustThirdVo);
			list = (List<LmtAdjustThirdVO>) beansCopy(lmtAdjustThirds, LmtAdjustThirdVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtAdjustThirdVO> queryAllCurrOrg(LmtAdjustThirdVO lmtAdjustThirdVo) {
		/**
		 * 时间区间的处理
		 */
		if(lmtAdjustThirdVo.getSignDate_b2e() != null && lmtAdjustThirdVo.getSignDate_b2e().toString() !="[]") {
			logger.info(lmtAdjustThirdVo.getSignDate_b2e().toString());
			lmtAdjustThirdVo.setSignDate_b(lmtAdjustThirdVo.getSignDate_b2e().get(0));
			lmtAdjustThirdVo.setSignDate_e(lmtAdjustThirdVo.getSignDate_b2e().get(1));
		}
		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<LmtAdjustThird> lmtAdjustThirds = lmtAdjustThirdDao.queryAllCurrOrgByPage(lmtAdjustThirdVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+lmtAdjustThirds.size());
		List<LmtAdjustThirdVO> list = null;
		try {
			pageSet(lmtAdjustThirds, lmtAdjustThirdVo);
			list = (List<LmtAdjustThirdVO>) beansCopy(lmtAdjustThirds, LmtAdjustThirdVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtAdjustThirdVO> queryAllCurrDownOrg(LmtAdjustThirdVO lmtAdjustThirdVo) {
		/**
		 * 时间区间的处理
		 */
		if(lmtAdjustThirdVo.getSignDate_b2e() != null && lmtAdjustThirdVo.getSignDate_b2e().toString() !="[]") {
			logger.info(lmtAdjustThirdVo.getSignDate_b2e().toString());
			lmtAdjustThirdVo.setSignDate_b(lmtAdjustThirdVo.getSignDate_b2e().get(0));
			lmtAdjustThirdVo.setSignDate_e(lmtAdjustThirdVo.getSignDate_b2e().get(1));
		}
		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<LmtAdjustThird> lmtAdjustThirds = lmtAdjustThirdDao.queryAllCurrDownOrgByPage(lmtAdjustThirdVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ lmtAdjustThirds.size());
		List<LmtAdjustThirdVO> list = null;
		try {
			pageSet(lmtAdjustThirds, lmtAdjustThirdVo);
			list = (List<LmtAdjustThirdVO>) beansCopy(lmtAdjustThirds, LmtAdjustThirdVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前产品种类下权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtAdjustThirdVO> queryAllCurrOwnerPrd(LmtAdjustThirdVO lmtAdjustThirdVo) {
		/**
		 * 时间区间的处理
		 */
		if(lmtAdjustThirdVo.getSignDate_b2e() != null && lmtAdjustThirdVo.getSignDate_b2e().toString() !="[]") {
			logger.info(lmtAdjustThirdVo.getSignDate_b2e().toString());
			lmtAdjustThirdVo.setSignDate_b(lmtAdjustThirdVo.getSignDate_b2e().get(0));
			lmtAdjustThirdVo.setSignDate_e(lmtAdjustThirdVo.getSignDate_b2e().get(1));
		}
		logger.debug("当前查询产品种类下信息的参数信息为:");
		List<LmtAdjustThird> lmtAdjustThirds = lmtAdjustThirdDao.queryAllCurrOwnerPrdByPage(lmtAdjustThirdVo);
		logger.debug("当前查询产品种类下数据信息的结果集数量为:"+ lmtAdjustThirds.size());
		List<LmtAdjustThirdVO> list = null;
		try {
			pageSet(lmtAdjustThirds, lmtAdjustThirdVo);
			list = (List<LmtAdjustThirdVO>) beansCopy(lmtAdjustThirds, LmtAdjustThirdVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	@Override
	public LmtAdjustThirdVO queryByGlobalSerno(LmtAdjustThirdVO lmtAdjustThirdVo) {
		logger.debug("当前查询参数信息为:"+ lmtAdjustThirdVo);
		try {
			LmtAdjustThird queryLmtAdjustThird = new LmtAdjustThird();
			beanCopy(lmtAdjustThirdVo, queryLmtAdjustThird);
			LmtAdjustThird queryRslLmtAdjustThird = lmtAdjustThirdDao.queryByGlobalSerno(queryLmtAdjustThird);
			if (Objects.nonNull(queryRslLmtAdjustThird)) {
				LmtAdjustThirdVO outLmtAdjustThirdVo = beanCopy(queryRslLmtAdjustThird, new LmtAdjustThirdVO());
				logger.debug("当前查询结果为:"+ outLmtAdjustThirdVo.toString());
				return outLmtAdjustThirdVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public LmtAdjustThirdVO queryByAdjAmtId(LmtAdjustThirdVO lmtAdjustThirdVo) {
		logger.debug("当前查询参数信息为:"+ lmtAdjustThirdVo);
		try {
			LmtAdjustThird queryLmtAdjustThird = new LmtAdjustThird();
			beanCopy(lmtAdjustThirdVo, queryLmtAdjustThird);
			LmtAdjustThird queryRslLmtAdjustThird = lmtAdjustThirdDao.queryByAdjAmtId(queryLmtAdjustThird);
			if (Objects.nonNull(queryRslLmtAdjustThird)) {
				LmtAdjustThirdVO outLmtAdjustThirdVo = beanCopy(queryRslLmtAdjustThird, new LmtAdjustThirdVO());
				logger.debug("当前查询结果为:"+ outLmtAdjustThirdVo.toString());
				return outLmtAdjustThirdVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public LmtAdjustThirdVO queryByBdReqSn(LmtAdjustThirdVO lmtAdjustThirdVo) {
		logger.debug("当前查询参数信息为:"+ lmtAdjustThirdVo);
		try {
			LmtAdjustThird queryLmtAdjustThird = new LmtAdjustThird();
			beanCopy(lmtAdjustThirdVo, queryLmtAdjustThird);
			LmtAdjustThird queryRslLmtAdjustThird = lmtAdjustThirdDao.queryByBdReqSn(queryLmtAdjustThird);
			if (Objects.nonNull(queryRslLmtAdjustThird)) {
				LmtAdjustThirdVO outLmtAdjustThirdVo = beanCopy(queryRslLmtAdjustThird, new LmtAdjustThirdVO());
				logger.debug("当前查询结果为:"+ outLmtAdjustThirdVo.toString());
				return outLmtAdjustThirdVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
}
